<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<script>var ctx="${ctx}";</script>
<div class="form-horizontal" role="form" >
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">标题:</label>
        <div class="col-md-9">
        	 <input id="title" value="${newgoods.title}"  type="text" placeholder="标题" class="form-control" name="title"/>
        </div>
    </div>
    	<div class="form-group">
	 	    <label class="col-md-3 col-sm-3 control-label">图片:</label>
	        <div class="col-md-9">
	        	 <div class="col-md-10">
		        	 <input class="fileInput" id="imageUploadify" type="file" name="file" accept="image/*"/>
		        	 <div class="imageUploadify">   
						<c:if test="${not empty(newgoods.image)}">
						<c:forEach items="${fn:split(newgodos.image,',')}" var="i">
							<img src="${i}" style="width: 60px;height: 60px">
						</c:forEach>
						</c:if>
					 </div>
		        </div>
	        </div>
	    </div>
    <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">分类:</label>
        <div class="col-md-9">
        	 <select id="catId" data-placeholder="选择商品分类" class="chosen-select full-width"  tabindex="4">
			</select>
        </div>
    </div>
    <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">品牌:</label>
        <div class="col-md-9">
        	 <select id="brandId" data-placeholder="选择商品分类" class="chosen-select full-width"  tabindex="4">
			</select>
        </div>
    </div>
    <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">是否上架：</label>
        <div class="col-md-9">
        	 	<input type="checkbox" class="js-switch" name="enable" checked="checked"/>
        </div>
    </div>
    
    <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">内容:</label>
        <div class="col-md-9">
        	 <script type="text/plain" id="editor"></script>
        </div>
    </div>
</div>
<script>
$(function(){
	//UE.getEditor('editor2').destroy();
	 //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
   UE.delEditor("editor");
 ue=UE.getEditor('editor',{
    //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
    toolbars: [[
	   'fullscreen', 'source', '|', 'undo', 'redo', '|',
       'bold', 'italic', 'underline', 'fontborder', 'removeformat', 'formatmatch', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist',
       'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
       'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
       'indent',
       'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
       'link', 'unlink','simpleupload', 'insertimage','insertvideo'
	 ]],
     //关闭字数统计
     wordCount:false,
     initialFrameHeight:200,
     //关闭elementPath
     elementPathEnabled:false
	})
})
</script>
<script>
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
elems.forEach(function(html) {
	var switchery = new Switchery(html);
});
$(function(){
	$("#catId").chosen({ width: '100%' });
	$("#brandId").chosen({ width: '100%' });
    $.ajax({  
		url:'${ctx}/goodsCat/list',  		 					
		type: 'POST',
		dataType:'json',  
		success:function(response){
			if(response.code==0){
				var html=[];
				var data=response.data||[];
				for(var i=0;i<data.length;i++){
					html.push('<option value="'+data[i].id+'">'+data[i].name+'</option>');
				}
				$("#catId").append(html.join(""));
				$("#catId").trigger("chosen:updated");
			}
		 }  
     });
    
    $.ajax({  
		url:'${ctx}/brand/list',  		 					
		type: 'POST',
		dataType:'json',  
		success:function(response){
			if(response.code==0){
				var html=[];
				var data=response.data||[];
				for(var i=0;i<data.length;i++){
					html.push('<option value="'+data[i].id+'">'+data[i].name+'</option>');
				}
				$("#brandId").append(html.join(""));
				$("#brandId").trigger("chosen:updated");
			}
		 }  
     });
}); 	

$("#imageUploadify").uploadify({
	'buttonImage':'${ctx}/static/js/plugins/uploadify/uploadify-button.png',
    'swf': '${ctx}/static/js/plugins/uploadify/uploadify.swf',
    'uploader':'${ctx}/file/uploadOss',
    'multi':false,
    'onFallback' : function() {//检测FLASH失败调用 
    	alert("您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试。");  
    },  
    'onUploadSuccess':function(file, data, response){
    	var jData = jQuery.parseJSON(data);
        $(".imageUploadify").html("<img src=\""+jData.data+"\" style=\"width: 60px;height: 60px;padding-left:5px;\">");
	}
});
</script>